﻿using System.Data;
using System.Data.SqlClient;
using Pantry.Commons;
using Pantry.DataAccess;
using Pantry.Entity;

namespace Pantry.Business
{
    public class VolunteersBus
    {
        private readonly VolunteersDao _volunteersDao;

        public VolunteersBus()
        {
            _volunteersDao = new VolunteersDao();
        }

        /// <summary>
        /// Selects the volunteers.
        /// </summary>
        /// <returns></returns>
        public DataTable SelectVolunteers(int premisesId)
        {
            return _volunteersDao.SelectVolunteers(premisesId);
        }

        /// <summary>
        /// Marks the activated.
        /// </summary>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public bool MarkActivated(bool isActive, int id)
        {
            try
            {
                var result = _volunteersDao.MarkActivated(isActive, id);
                return (result != 0);
            }
            catch (SqlException exception)
            {
                ExceptionHandler.WriteErrorLog(exception);
                return false;
            }
        }

        /// <summary>
        /// Inserts the volunteers.
        /// </summary>
        /// <param name="volunteers">The volunteers.</param>
        /// <returns></returns>
        public int InsertVolunteers(Volunteers volunteers)
        {
            return _volunteersDao.InsertVolunteers(volunteers);
        }

        /// <summary>
        /// Updates the volunteers.
        /// </summary>
        /// <param name="volunteers">The volunteers.</param>
        /// <param name="id"> </param>
        /// <returns></returns>
        public int UpdateVolunteers(Volunteers volunteers, int id)
        {
            return _volunteersDao.UpdateVolunteers(volunteers, id);
        }

        /// <summary>
        /// Selects the volunteers by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Volunteers SelectVolunteersById(int id)
        {
            return _volunteersDao.SelectVolunteersById(id);
        }
    }
}
